package com.example.smokealarm.controller;

import com.example.smokealarm.model.LoginAccount;
import com.example.smokealarm.model.LoginRequest;
import com.example.smokealarm.model.LoginResponse;
import com.example.smokealarm.service.LoginAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/accounts")
public class LoginAccountController {
    @Autowired
    private LoginAccountService service;

    @GetMapping
    public List<LoginAccount> getAllAccounts() {
        return service.getAllAccounts();
    }

    @PostMapping
    public LoginAccount createAccount(@RequestBody LoginAccount account) {
        return service.createAccount(account);
    }

    @PostMapping("/login")
    public LoginResponse login(@RequestBody LoginRequest loginRequest) {
        return service.login(loginRequest);
    }

    @PostMapping("/register")
    public LoginResponse register(@RequestBody LoginAccount account) {
        return service.register(account);
    }
}